home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo2.zoo / demo / ex / ex.h < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-24  |  13.1 KB  |  434 lines

  1. /*
  2.  * Copyright (c) 1980 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  *
  6.  *    @(#)ex.h    7.8 (Berkeley) 3/9/87
  7.  *    @(#)ex.h    1.2 (Bellcore)    87/04/24
  8.  */
  9.  
  10. #ifdef V6
  11. #include <retrofit.h>
  12. #endif
  13.  
  14. /*
  15.  * Ex version 3 (see exact version in ex_cmds.c, search for /Version/)
  16.  *
  17.  * Mark Horton, UC Berkeley
  18.  * Bill Joy, UC Berkeley
  19.  * November 1979
  20.  *
  21.  * This file contains most of the declarations common to a large number
  22.  * of routines.  The file ex_vis.h contains declarations
  23.  * which are used only inside the screen editor.
  24.  * The file ex_tune.h contains parameters which can be diddled per installation.
  25.  *
  26.  * The declarations relating to the argument list, regular expressions,
  27.  * the temporary file data structure used by the editor
  28.  * and the data describing terminals are each fairly substantial and
  29.  * are kept in the files ex_{argv,re,temp,tty}.h which
  30.  * we #include separately.
  31.  *
  32.  * If you are going to dig into ex, you should look at the outline of the
  33.  * distribution of the code into files at the beginning of ex.c and ex_v.c.
  34.  * Code which is similar to that of ed is lightly or undocumented in spots
  35.  * (e.g. the regular expression code).  Newer code (e.g. open and visual)
  36.  * is much more carefully documented, and still rough in spots.
  37.  *
  38.  * Please forward bug reports to
  39.  *
  40.  *    Mark Horton
  41.  *    Computer Science Division, EECS
  42.  *    EVANS HALL
  43.  *    U.C. Berkeley 94704
  44.  *    (415) 642-4948
  45.  *    (415) 642-1024 (dept. office)
  46.  *
  47.  * or to csvax.mark@berkeley on the ARPA-net.  I would particularly like to hear
  48.  * of additional terminal descriptions you add to the termcap data base.
  49.  */
  50.  
  51. #ifndef    vms
  52. #include <sys/param.h>
  53. #else
  54. #define    MAXBSIZE    1024    /* Maximum block size */
  55. #include <types.h>
  56. #endif
  57. #include <ctype.h>
  58. #include <errno.h>
  59. #include <signal.h>
  60. #include <setjmp.h>
  61. #ifndef    vms
  62. #include <sys/stat.h>
  63. #else
  64. #include <stat.h>
  65. #endif
  66.  
  67. #ifndef var
  68. #define var    extern
  69. #endif
  70. /*
  71.  *    The following little dance copes with the new USG tty handling.
  72.  *    This stuff has the advantage of considerable flexibility, and
  73.  *    the disadvantage of being incompatible with anything else.
  74.  *    The presence of the symbol USG3TTY will indicate the new code:
  75.  *    in this case, we define CBREAK (because we can simulate it exactly),
  76.  *    but we won't actually use it, so we set it to a value that will
  77.  *    probably blow the compilation if we goof up.
  78.  */
  79. #ifdef USG3TTY
  80. #include <termio.h>
  81. #define CBREAK xxxxx
  82. #else
  83. #ifndef    vms
  84. #include <sgtty.h>
  85. #else
  86. #include "vmstty.h"
  87. #endif
  88. #endif
  89.  
  90. extern    int errno;
  91.  
  92. #ifndef VMUNIX
  93. typedef    short    line;
  94. #else
  95. typedef    int    line;
  96. #endif
  97. typedef    short    bool;
  98.  
  99. #include "ex_tune.h"
  100. #include "ex_vars.h"
  101. /*
  102.  * Options in the editor are referred to usually by "value(name)" where
  103.  * name is all uppercase, i.e. "value(PROMPT)".  This is actually a macro
  104.  * which expands to a fixed field in a static structure and so generates
  105.  * very little code.  The offsets for the option names in the structure
  106.  * are generated automagically from the structure initializing them in
  107.  * ex_data.c... see the shell script "makeoptions".
  108.  */
  109. struct    option {
  110.     char    *oname;
  111.     char    *oabbrev;
  112.     short    otype;        /* Types -- see below */
  113.     short    odefault;    /* Default value */
  114.     short    ovalue;        /* Current value */
  115.     char    *osvalue;
  116. };
  117.  
  118. #define    ONOFF    0
  119. #define    NUMERIC    1
  120. #define    STRING    2        /* SHELL or DIRECTORY */
  121. #define    OTERM    3
  122.  
  123. #define    value(a)    options[a].ovalue
  124. #define    svalue(a)    options[a].osvalue
  125.  
  126. extern     struct    option options[NOPTS + 1];
  127.  
  128. #ifdef vms
  129. #define    st_blksize    st_fab_mrs
  130. #define    _exit(n)    vms_exit(n)
  131. #define    fork()        vfork()
  132. #endif
  133.  
  134. /*
  135.  * The editor does not normally use the standard i/o library.  Because
  136.  * we expect the editor to be a heavily used program and because it
  137.  * does a substantial amount of input/output processing it is appropriate
  138.  * for it to call low level read/write primitives directly.  In fact,
  139.  * when debugging the editor we use the standard i/o library.  In any
  140.  * case the editor needs a printf which prints through "putchar" ala the
  141.  * old version 6 printf.  Thus we normally steal a copy of the "printf.c"
  142.  * and "strout" code from the standard i/o library and mung it for our
  143.  * purposes to avoid dragging in the stdio library headers, etc if we
  144.  * are not debugging.  Such a modified printf exists in "printf.c" here.
  145.  */
  146. #ifdef TRACE
  147. # include <stdio.h>
  148.     var    FILE    *trace;
  149.     var    bool    trubble;
  150.     var    bool    techoin;
  151.     var    char    tracbuf[BUFSIZ];
  152. #else
  153. # ifdef    VMUNIX
  154. #    define    BUFSIZ    1024
  155. # else
  156. #  ifdef u370
  157. #    define    BUFSIZ    4096
  158. #  else
  159. #    define    BUFSIZ    512
  160. #  endif
  161. # endif
  162. #    define    NULL    0
  163. #    define    EOF    -1
  164. #endif
  165.  
  166. /*
  167.  * Character constants and bits
  168.  *
  169.  * The editor uses the QUOTE bit as a flag to pass on with characters
  170.  * e.g. to the putchar routine.  The editor never uses a simple char variable.
  171.  * Only arrays of and pointers to characters are used and parameters and
  172.  * registers are never declared character.
  173.  */
  174. #define    QUOTE    0200
  175. #define    TRIM    0177
  176. #ifndef vms
  177. #undef CTRL
  178. #endif
  179. #define    CTRL(c)    ('c' & 037)
  180. #define    NL    CTRL(j)
  181. #define    CR    CTRL(m)
  182. #define    DELETE    0177        /* See also ATTN, QUIT in ex_tune.h */
  183. #define    ESCAPE    033
  184.  
  185. /*
  186.  * Miscellaneous random variables used in more than one place
  187.  */
  188. var    bool    aiflag;        /* Append/change/insert with autoindent */
  189. var    bool    anymarks;    /* We have used '[a-z] */
  190. var    int    chng;        /* Warn "No write" */
  191. var    char    *Command;
  192. var    short    defwind;    /* -w# change default window size */
  193. var    int    dirtcnt;    /* When >= MAXDIRT, should sync temporary */
  194. #ifdef TIOCLGET
  195. var    bool    dosusp;        /* Do SIGTSTP in visual when ^Z typed */
  196. #endif
  197. var    bool    edited;        /* Current file is [Edited] */
  198. var    line    *endcore;    /* Last available core location */
  199. extern     bool    endline;    /* Last cmd mode command ended with \n */
  200. #ifdef EXSTRINGS
  201. var    short    erfile;        /* Error message file unit */
  202. #endif
  203. var    line    *fendcore;    /* First address in line pointer space */
  204. var    char    file[FNSIZE];    /* Working file name */
  205. var    char    genbuf[MAXBSIZE]; /* Working buffer when manipulating linebuf */
  206. var    bool    hush;        /* Command line option - was given, hush up! */
  207. var    char    *globp;        /* (Untyped) input string to command mode */
  208. var    bool    holdcm;        /* Don't cursor address */
  209. var    bool    inappend;    /* in ex command append mode */
  210. var    bool    inglobal;    /* Inside g//... or v//... */
  211. var    char    *initev;    /* Initial : escape for visual */
  212. var    bool    inopen;        /* Inside open or visual */
  213. var    char    *input;        /* Current position in cmd line input buffer */
  214. var    bool    intty;        /* Input is a tty */
  215. var    short    io;        /* General i/o unit (auto-closed on error!) */
  216. extern     short    lastc;        /* Last character ret'd from cmd input */
  217. var    bool    laste;        /* Last command was an "e" (or "rec") */
  218. var    char    lastmac;    /* Last macro called for ** */
  219. var    char    lasttag[TAGSIZE];    /* Last argument to a tag command */
  220. var    char    *linebp;    /* Used in substituting in \n */
  221. var    char    linebuf[LBSIZE];    /* The primary line buffer */
  222. var    bool    listf;        /* Command should run in list mode */
  223. var    char    *loc1;        /* Where re began to match (in linebuf) */
  224. var    char    *loc2;        /* First char after re match (") */
  225. var    line    names['z'-'a'+2];    /* Mark registers a-z,' */
  226. var    int    notecnt;    /* Count for notify (to visual from cmd) */
  227. var    bool    numberf;    /* Command should run in number mode */
  228. var    char    obuf[BUFSIZ];    /* Buffer for tty output */
  229. var    short    oprompt;    /* Saved during source */
  230. extern    short    ospeed;        /* Output speed (from gtty) */
  231. var    int    otchng;        /* Backup tchng to find changes in macros */
  232. var    short    peekc;        /* Peek ahead character (cmd mode input) */
  233. var    char    *pkill[2];    /* Trim for put with ragged (LISP) delete */
  234. var    bool    pfast;        /* Have stty -nl'ed to go faster */
  235. var    int    pid;        /* Process id of child */
  236. var    int    ppid;        /* Process id of parent (e.g. main ex proc) */
  237. var    jmp_buf    resetlab;    /* For error throws to top level (cmd mode) */
  238. var    int    rpid;        /* Pid returned from wait() */
  239. var    bool    ruptible;    /* Interruptible is normal state */
  240. var    bool    seenprompt;    /* 1 if have gotten user input */
  241. var    bool    shudclob;    /* Have a prompt to clobber (e.g. on ^D) */
  242. var    int    status;        /* Status returned from wait() */
  243. var    int    tchng;        /* If nonzero, then [Modified] */
  244. extern    short    tfile;        /* Temporary file unit */
  245. var    bool    vcatch;        /* Want to catch an error (open/visual) */
  246. var    jmp_buf    vreslab;    /* For error throws to a visual catch */
  247. var    bool    writing;    /* 1 if in middle of a file write */
  248. var    int    xchng;        /* Suppresses multiple "No writes" in !cmd */
  249. var    long    bsize;        /* Block size for disk i/o */
  250.  
  251. /*
  252.  * Macros
  253.  */
  254. #define    CP(a, b)    (ignore(strcpy(a, b)))
  255.             /*
  256.              * FIXUNDO: do we want to mung undo vars?
  257.              * Usually yes unless in a macro or global.
  258.              */
  259. #define FIXUNDO        (inopen >= 0 && (inopen || !inglobal))
  260. #define ckaw()        {if (chng && value(AUTOWRITE)) wop(0);}
  261. #define    copy(a,b,c)    Copy((char *) a, (char *) b, c)
  262. #define    eq(a, b)    ((a) && (b) && strcmp(a, b) == 0)
  263. #define    getexit(a)    copy(a, resetlab, sizeof (jmp_buf))
  264. #define    lastchar()    lastc
  265. #define    outchar(c)    (*Outchar)(c)
  266. #define    pastwh()    (ignore(skipwh()))
  267. #define    pline(no)    (*Pline)(no)
  268. #define    reset()        longjmp(resetlab,1)
  269. #define    resexit(a)    copy(resetlab, a, sizeof (jmp_buf))
  270. #define    setexit()    setjmp(resetlab)
  271. #define    setlastchar(c)    lastc = c
  272. #define    ungetchar(c)    peekc = c
  273.  
  274. #define    CATCH        vcatch = 1; if (setjmp(vreslab) == 0) {
  275. #define    ONERR        } else { vcatch = 0;
  276. #define    ENDCATCH    } vcatch = 0;
  277.  
  278. /*
  279.  * Environment like memory
  280.  */
  281. var    char    altfile[FNSIZE];    /* Alternate file name */
  282. extern     char    direct[ONMSZ];        /* Temp file goes here */
  283. extern     char    shell[ONMSZ];        /* Copied to be settable */
  284. extern     char    ttytype[ONMSZ];        /* A long and pretty name */
  285. var    char    uxb[UXBSIZE + 2];    /* Last !command for !! */
  286.  
  287. /*
  288.  * The editor data structure for accessing the current file consists
  289.  * of an incore array of pointers into the temporary file tfile.
  290.  * Each pointer is 15 bits (the low bit is used by global) and is
  291.  * padded with zeroes to make an index into the temp file where the
  292.  * actual text of the line is stored.
  293.  *
  294.  * To effect undo, copies of affected lines are saved after the last
  295.  * line considered to be in the buffer, between dol and unddol.
  296.  * During an open or visual, which uses the command mode undo between
  297.  * dol and unddol, a copy of the entire, pre-command buffer state
  298.  * is saved between unddol and truedol.
  299.  */
  300. var    line    *addr1;            /* First addressed line in a command */
  301. var    line    *addr2;            /* Second addressed line */
  302. var    line    *dol;            /* Last line in buffer */
  303. var    line    *dot;            /* Current line */
  304. var    line    *one;            /* First line */
  305. var    line    *truedol;        /* End of all lines, including saves */
  306. var    line    *unddol;        /* End of undo saved lines */
  307. var    line    *zero;            /* Points to empty slot before one */
  308.  
  309. /*
  310.  * Undo information
  311.  *
  312.  * For most commands we save lines changed by salting them away between
  313.  * dol and unddol before they are changed (i.e. we save the descriptors
  314.  * into the temp file tfile which is never garbage collected).  The
  315.  * lines put here go back after unddel, and to complete the undo
  316.  * we delete the lines [undap1,undap2).
  317.  *
  318.  * Undoing a move is much easier and we treat this as a special case.
  319.  * Similarly undoing a "put" is a special case for although there
  320.  * are lines saved between dol and unddol we don't stick these back
  321.  * into the buffer.
  322.  */
  323. var    short    undkind;
  324.  
  325. var    line    *unddel;    /* Saved deleted lines go after here */
  326. var    line    *undap1;    /* Beginning of new lines */
  327. var    line    *undap2;    /* New lines end before undap2 */
  328. var    line    *undadot;    /* If we saved all lines, dot reverts here */
  329.  
  330. #define    UNDCHANGE    0
  331. #define    UNDMOVE        1
  332. #define    UNDALL        2
  333. #define    UNDNONE        3
  334. #define    UNDPUT        4
  335.  
  336. #ifdef CRYPT
  337. /*
  338.  * Various miscellaneous flags and buffers needed by the encryption routines.
  339.  */
  340. #define    KSIZE   9       /* key size for encryption */
  341. #define    KEYPROMPT       "Key: "
  342. var    int    xflag;        /* True if we are in encryption mode */
  343. var    int    xtflag;        /* True if the temp file is being encrypted */
  344. var    int    kflag;        /* True if the key has been accepted */
  345. var    char    perm[768];
  346. var    char    tperm[768];
  347. var    char    *key;
  348. var    char    crbuf[CRSIZE];
  349. char    *getpass();
  350. #endif
  351.  
  352. /*
  353.  * Function type definitions
  354.  */
  355. #define    NOSTR    (char *) 0
  356. #define    NOLINE    (line *) 0
  357.  
  358. extern    int    (*Outchar)();
  359. extern    int    (*Pline)();
  360. extern    int    (*Put_char)();
  361. var    int    (*oldhup)();
  362. int    (*setlist())();
  363. int    (*setnorm())();
  364. int    (*setnorm())();
  365. int    (*setnumb())();
  366. line    *address();
  367. char    *cgoto();
  368. char    *genindent();
  369. char    *getblock();
  370. char    *getenv();
  371. #ifdef    vms
  372. char    *getlog();
  373. #endif
  374. line    *getmark();
  375. char    *longname();
  376. char    *mesg();
  377. char    *place();
  378. char    *plural();
  379. line    *scanfor();
  380. line    *setin();
  381. char    *strcat();
  382. char    *strcpy();
  383. char    *strend();
  384. char    *tailpath();
  385. char    *tgetstr();
  386. char    *tgoto();
  387. char    *ttyname();
  388. line    *vback();
  389. char    *vfindcol();
  390. char    *vgetline();
  391. char    *vinit();
  392. char    *vpastwh();
  393. char    *vskipwh();
  394. int    put();
  395. int    putreg();
  396. int    YANKreg();
  397. int    ex_delete();
  398. int    execl();
  399. int    filter();
  400. int    getfile();
  401. int    getsub();
  402. int    gettty();
  403. int    join();
  404. int    listchar();
  405. off_t    lseek();
  406. int    normchar();
  407. int    normline();
  408. int    numbline();
  409. var    int    (*oldquit)();
  410. int    onhup();
  411. int    onintr();
  412. int    onsusp();
  413. int    putch();
  414. int    shift();
  415. int    termchar();
  416. int    vfilter();
  417. #ifdef CBREAK
  418. int    vintr();
  419. #endif
  420. int    vputch();
  421. int    vshftop();
  422. int    yank();
  423.  
  424. /*
  425.  * C doesn't have a (void) cast, so we have to fake it for lint's sake.
  426.  */
  427. #ifdef lint
  428. #    define    ignore(a)    Ignore((char *) (a))
  429. #    define    ignorf(a)    Ignorf((int (*) ()) (a))
  430. #else
  431. #    define    ignore(a)    a
  432. #    define    ignorf(a)    a
  433. #endif
  434.